﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KPIS.GERP.GBMS.BLL;
using KPIS.GERP.GBMS.IBLL;
using KPIS.GERP.GBMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GBMS.APP_UI
{
    public partial class ExpenseGroupCombo : System.Web.UI.UserControl
    {
        public RadComboBox ctrChild;
        private IExpenseGroupBLL expGrp = new ExpenseGroupBLL();
        private IExpenseBLL exp = new ExpenseBLL();
        private IProject proj = new Project_BLL();
        private string expType;

        public string ExpenseType
        {
            get { return expType; }
            set { expType = value; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            cbExpenseGroup.AutoPostBack = ctrChild != null;
        }

        public void LoadExpenseGroupComboBox()
        {
            LoadExpenseGroupComboBox(0, "", "", "", 0, 0);
        }

        public void LoadExpenseGroupComboBox(int seq, string code, string name, string descr, int parent, int source)
        {
            cbExpenseGroup.DataSource = expGrp.Search(seq, code, name, descr, parent, source);
            cbExpenseGroup.DataBind();

            cbExpenseGroup.Items.Insert(0, new RadComboBoxItem("- เลือกงบรายจ่าย -", ""));
        }

        protected void cbExpenseGroup_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            string val = "";

            if (cbExpenseGroup.SelectedIndex > 0)
            {
                val = cbExpenseGroup.SelectedValue;

                if (ctrChild != null)
                {
                    RadTreeView tView = (RadTreeView)ctrChild.Items[0].FindControl("tExpense");

                    if(tView.Nodes.Count > 0)
                        tView.Nodes.RemoveAt(0);

                    IList<TreeViewInfo> tInfo = new List<TreeViewInfo>();

                    tView.DataSource = exp.TreeView(tInfo, true, val);
                    tView.DataBind();

                    ctrChild.Items.Insert(0, new RadComboBoxItem("- เลือกค่าใช้จ่าย -"));
                    ctrChild.Focus();
                }
            }
            else
                if (ctrChild != null)
                    ctrChild.Items.Clear();
        }
    }
}